package com.cloud.api.myenum;

/**
 * @author 杨斌
 * 2025-02-2025-02-11
 */
public enum VinYear {
    A(2010),
    B(2011),
    C(2012),
    D(2013),
    E(2014),
    F(2015),
    G(2016),
    H(2017),
    J(2018),
    K(2019),
    L(2020),
    M(2021),
    N(2022),
    P(2023),
    R(2024),
    S(2025),
    T(2026),
    V(2027),
    W(2028),
    X(2029),
    Y(2030);

    private final int year;

    VinYear(int year) {
        this.year = year;
    }

    public int getYear() {
        return year;
    }

//    public static String fromChar(char vinYearChar) {
//        for (VinYear vinYear : values()) {
//            if (vinYear.name().equals(String.valueOf(vinYearChar))) {
//                return String.valueOf(vinYear.getYear());
//            }
//        }
//        // 如果无法匹配，返回原始字母
//        return String.valueOf(vinYearChar);
//    }

    public static String fromChar(char vinYearChar) {
        // 处理数字1-9（对应2001-2009）
        if (Character.isDigit(vinYearChar)) {
            int num = Character.getNumericValue(vinYearChar);
            if (num >= 1 && num <= 9) {
                return String.valueOf(2000 + num);
            } else {
                return String.valueOf(vinYearChar);
            }
        }
        // 处理字母A-Y（对应2010-2030）
        for (VinYear vinYear : values()) {
            if (vinYear.name().charAt(0) == vinYearChar) {
                return String.valueOf(vinYear.getYear());
            }
        }
        // 无法匹配的字符返回原值
        return String.valueOf(vinYearChar);
    }
}
